package com.hfy.user.controller;

import com.alibaba.fastjson.JSON;
import com.hfy.model.dto.UpdateDto;
import com.hfy.model.po.user.UserCommentPo;
import com.hfy.user.service.InfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import result.Result;
import utils.CheckUtils;

/**
 * @ author 韩
 * time: 2024/5/20 2:14
 */
@RestController
@Tag(name = "个人信息的接口类" ,description = "提供个人信息的修改什么的接口")
@RequestMapping("/info")
public class InfoController {

    @Autowired
    private InfoService infoService;

    @PostMapping("/update")
    @Deprecated
    // todo 需要修改
    @Operation(summary = "更新信息")
    @Parameters(@Parameter(description = ""))
    public Result updateInfo(@RequestParam("avatar") MultipartFile avatar, @RequestParam("jsonData") String jsonDataStr) {
        UpdateDto dto = JSON.parseObject(jsonDataStr, UpdateDto.class);
        return infoService.updateInfo(avatar,dto);
    }

    @GetMapping("/get")
    @Operation(summary = "获取用户的信息")
    @Parameters(@Parameter(name = "用uuid生成的token进行redis查询获取数据",description = ""))
    public Result getInfo(@RequestParam("token") String token) {
        return infoService.getInfo(token);
    }


    @GetMapping("/get_by_account/{account}")
    @Operation(summary = "主要是供feign接口调用获取用户的信息")
    @Parameters(@Parameter(name = "account",description = "账号"))
    public UserCommentPo getInfoByAccount(@PathVariable("account") Long account) {
        return infoService.getInfoByAccount(account);
    }


    @GetMapping("/page/{account}/{mineAccount}")
    @Operation(summary = "对其他用户页面所需信息进行获取展示")
    @Parameters({@Parameter(name = "account",description = "账号"),
            @Parameter(name = "mineAccount",description = "我的账号")}
    )
    public Result getPageInfoByAccount(@PathVariable("account") String account, @PathVariable("mineAccount") String mineAccount) {
        if (!CheckUtils.theStringIsLong(account)) {
            return Result.error("账号只能为一串数字");
        }
        if (!CheckUtils.theStringIsLong(mineAccount)) {
            return Result.error("账号只能为一串数字");
        }
        return infoService.getPageInfoByAccount(Long.parseLong(account), Long.parseLong(mineAccount));
    }

//    @DeleteMapping("/logoff")
//    @Operation(summary = "注销用户")

}
